﻿using AutoMapper;
using B.S.BasicData.Api.Read.Application.Command.RBAC;
using B.S.BasicData.Api.Read.DTO;
using B.S.BasicData.Domian.Entities.Account;
using B.S.BasicData.Domian.Entities.RBAC;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.RBAC
{
    public class GetBuHandler : IRequestHandler<GetBuCommand, ApiResult<List<ShowDTO>>>
    {
        private readonly IBaseRepository<AccountModel> accountRepo;
        private readonly IMapper mapper;

        public GetBuHandler(IBaseRepository<AccountModel> accountRepo, IMapper mapper)
        {
            this.accountRepo = accountRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<ShowDTO>>> Handle(GetBuCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<List<ShowDTO>>();
            var Account = accountRepo.GetAll().Where(x=>x.bid==request.Bid).ToList();
            var entity=mapper.Map<List<ShowDTO>>(Account);
            res.Message = "查询用户信息成功";
            res.Code=ApiEnum.Ok;
            res.Data = entity.ToList();
            return Task.FromResult(res);
        }
    }
}
